﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using Medianamik.Core.Security;
using System.Web.UI.WebControls;
using Medianamik.Globalization;
using Medianamik.Core;
using Medianamik.Core.Interfaces;

namespace Medianamik.UI.Controls
{
    [ToolboxData("<{0}:NodePermissionSelector runat=server></{0}:NodePermissionSelector>")]
    public class NodePermissionSelector : PermissionSelector
    {

        #region Fields

        
        #endregion

        #region Events

        

        #endregion

        #region Properties

        protected override PermissionType PermissionType
        {
            get { return PermissionType.NodePermission; }
        }

        private PermissionColumns _displayedPermissions = PermissionColumns.All;
        protected override PermissionColumns DisplayedPermissions
        {
            get
            {
                return _displayedPermissions &= ~PermissionColumns.Create;
            }
            set { _displayedPermissions = value; }
        }

        #endregion

        #region Methods

        protected override string GetObjectName(Guid objectID)
        {
            return Utility.GetFriendlyIdentifier(NodeManager.GetNode(objectID), 
                        MedianamikContext.Current.CurrentUICulture.Name);
        }

        protected override InheritedPermission GetInheritedPermissionForGroup(IGroup group)
        {
            return SecurityManager.GetInheritedNodePermissionsByGroupId(group.GroupId)
                .SingleOrDefault(p => p.SecuredObjectId.Equals(SecuredObjectId));
        }

        protected override Permission GetPermissionForGroup(IGroup group)
        {
            return SecurityManager.GetNodePermissionsByGroupId(group.GroupId )
                .SingleOrDefault(p => p.SecuredObjectId.Equals(SecuredObjectId));
        }

        #endregion
        
    }
}
